<div class="form">
    <script>
    </script>
<?php $form=$this->beginWidget('CActiveForm', array(
	'id'=>'customers-form',
	'enableAjaxValidation'=>false,
        
        'htmlOptions'=>array(
            'enctype'=>'multipart/form-data',
        )
      
    
)); 
    $discount=$model->discount;
    $latecharge=$model->latecharge;
    
    if($model->isNewRecord){
        $latecharge=$discount='0.00';
        
    }
   // $model->terms = 2;//Default NET 30
?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>
        <div class="row">
            
            <?php echo $form->labelEx($model,'image'); ?>
         

            <?php echo $form->fileField($model,'file');?>
            <?php echo $form->error($model,'file'); ?>
        </div>
   
	<div class="row">
            <?php echo $form->labelEx($model,'custno'); ?>
            <?php echo $form->textField($model,'custno',array('readonly'=>true));?>                        
            <?php echo $form->error($model,'custno'); ?>
	</div>
      
	<div class="row">
		<?php echo $form->labelEx($model,'lastname'); ?>
		<?php echo $form->textField($model,'lastname',array('size'=>50,'maxlength'=>50)); ?>
		<?php echo $form->error($model,'lastname'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'firstname'); ?>
		<?php echo $form->textField($model,'firstname',array('size'=>25,'maxlength'=>25)); ?>
		<?php echo $form->error($model,'firstname'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'add1'); ?>
		<?php echo $form->textField($model,'add1',array('size'=>50,'maxlength'=>50)); ?>
		<?php echo $form->error($model,'add1'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'add2'); ?>
		<?php echo $form->textField($model,'add2',array('size'=>50,'maxlength'=>50)); ?>
		<?php echo $form->error($model,'add2'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'city'); ?>
		<?php echo $form->textField($model,'city',array('size'=>30,'maxlength'=>30)); ?>
		<?php echo $form->error($model,'city'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'state'); ?>
		<?php echo $form->dropDownList($model,'state',getStateList()); ?>
		<?php echo $form->error($model,'state'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'zip'); ?>
		<?php echo $form->textField($model,'zip',array('size'=>10,'maxlength'=>10)); ?>
		<?php echo $form->error($model,'zip'); ?>
	</div>

    <div class="row">
        <?php echo $form->labelEx($model,'county');?>
        <?php echo $form->textField($model,'county');?>
        <div class="model-data">
            <a href='javascript:void(0)' onclick="searchCounty()">Lookup County</a>
        </div>
        <?php echo $form->error($model,'county');?>
    </div>

    <?php if($model->isNewRecord):?>
	<div class="row">
		<?php echo $form->labelEx($model,'creditrate'); ?>
		<?php echo $form->textField($model,'creditrate',array('size'=>7,'maxlength'=>7)); ?>
		<?php echo $form->error($model,'creditrate'); ?>
	</div>
    <?php endif;?>

	<div class="row">
		<?php echo $form->labelEx($model,'terms'); ?>
		<?php echo $form->dropDownList($model,'terms',$model->termList); ?>
		<?php echo $form->error($model,'terms'); ?>
	</div>

    <?php if($model->isNewRecord):?>
	<div class="row">
		<?php echo $form->labelEx($model,'pricecode'); ?>
		<?php echo $form->dropDownList($model,'pricecode',$model->getPriceCode()); ?>
		<?php echo $form->error($model,'pricecode'); ?>
	</div>

	
    <?php endif;?>
        
        <?php echo $form->hiddenField($model,'custref',array('size'=>15,'maxlength'=>15)); ?>

	
		<?php echo $form->hiddenField($model,'statement'); ?>
	
    <?php if($model->isNewRecord):?>
	
    <?php endif;?>

	<div class="row">
		<?php echo $form->labelEx($model,'requirepo'); ?>
		<?php echo $form->checkBox($model,'requirepo'); ?>
		<?php echo $form->error($model,'requirepo'); ?>
	</div>


		<?php echo $form->hiddenField($model,'post'); ?>
	
        



		<?php echo $form->hiddenField($model,'defpriority',array('size'=>6,'maxlength'=>6)); ?>
	
	<div class="row">
		<?php echo $form->labelEx($model,'salesperson'); ?>
		<?php //echo $form->dropDownList($model,'salesperson',$model->getSalePersonList()); ?>
		<?php echo $form->textField($model,'salesperson',array('readonly'=>true,'value'=>getUserRealname(Yii::app()->user->name))); ?>
		<?php echo $form->error($model,'salesperson'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'customerinactive'); ?>
		<?php echo $form->dropDownList($model,'customerinactive',$model->activeList); ?>
		<?php echo $form->error($model,'customerinactive'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'website'); ?>
		<?php echo $form->textField($model,'website',array('size'=>60,'maxlength'=>128)); ?>
		<?php echo $form->error($model,'website'); ?>
	</div>

    <?php if($model->isNewRecord):?>
	<div class="row">
		<?php echo $form->labelEx($model,'emailstatement'); ?>
		<?php echo $form->checkBox($model,'emailstatement'); ?>
		<?php echo $form->error($model,'emailstatement'); ?>
	</div>
    <?php endif; ?>
	
        
	<div class="row">
		<?php echo $form->labelEx($model,'notes'); ?>
		<?php echo $form->textArea($model,'notes',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'notes'); ?>
	</div>

	<div class="row_buttons">
		<?php 
                    $buttonText=NULL;
                    if($model->lockby!=NULL && $model->lockby!=Yii::app()->user->name){
                        $buttonText='Lock by '.Users::getUserNameByEmail($model->lockby);
                    }else{
                        if($model->isNewRecord){
                            $buttonText='Create';
                        }else{
                            $buttonText='Save';
                        }
                    }
                    echo CHtml::submitButton($buttonText,array(
                    'id'=>'btnSubmitForm',                    
                    'disabled'=>($model->lockby!=NULL && $model->lockby!=Yii::app()->user->name)?'disabled':NULL,
                    
                )); ?>
	</div>

<?php $this->endWidget(); ?>

</div><!-- form -->

<?php 
Yii::app()->clientScript->registerScript('ajax_county', "
function searchCounty(){
  $.get('index.php?r=salespersonportal/ajax/lookupCounty&zipcode='+$('#Customers_zip').val(),function(data){
    $('#Customers_county').val(data);
})
}",
  CClientScript::POS_END);

?>
